<?php
namespace app\supermanager\controller;
use app\common\traits\controller\TraitController;
class Caravan extends \think\Controller
{
	use TraitController;
	public function init(){
		if (!model('Managers')->checkLogin()) {
            $this->redirect('@manager/login');
            exit;
        }
	    $this->model = model('Caravans');
		$this->list_route = url('/caravans');
	}

    /**
     * GET shwo caravan info list
     * @return [type] [description]
     */
    public function getIndex()
    {	//分公司
		$branchs = model('Filiales')->column('name','id');
        $this->assign('branchs',$branchs);
        $list = model('Caravans')->getCaravansLists(input('get.'));
        $this->assign('list',$list);
        return view('caravan/index');
    }
	
	/**
	 * 查看资源详情
	 */
	public function getRead(){
		$ziduans = $this->model->getZiduna();
		$this->assign('ziduans',$ziduans);
		$this->assign('speed',$this->model->speed());
		$this->assign('driverType',$this->model->driverType());
		$list = $this->model->where('id',$this->request->get('id'))->find();
	    //获取当前房车所在某时间段的状态 === 1 表示已激活
	    if ($list->getData('status') === 1) {
	        $share = model('common/Caravans')->getCaravanStatus($this -> request -> get('id'));
	        $this->assign('share',$share['shares']);//获取日历表房车的分享状态
	        $this->assign('trusts',$share['trusts']);//获取日历表房车的出租状态
	        //$this->assign('disables',$share['disables']);//获取日历表房车的订单状态
	        $this->assign('sharedisables',$share['disables']['shares']);//获取日历表房车分享订单状态
	        $this->assign('trustdisables',$share['disables']['trusts']);//获取日历表房车托管订单状态
	        $this->assign('notrustorderdisables',$share['disables']['trustsnoorder']);//获取日历表房车无订单托管订单状态
	        $rentPrice = model('Calendar')->where('caravan_id',$this -> request -> get('id'))->where('trusts','1')->column('single_day_price', 'datetimes');
	        $this->assign('rentPrice',json_encode($rentPrice));
	    }
		return view('caravan/read',['list' =>$list]);
	}
	
	/**
	 * 设置首页热门
	 */
	public function setHot($id,$hot){
		if($this->model->where('hot',1)->count('hot')===10){
			$this->success('首页热门数量已满10个');
		}
		if($this->model->where(['id'=>$id])->update(['hot'=>$hot])===1){
			$this->success('设置成功',$this->list_route);
		}
		$this->error('设置失败');
	}
	
	/**
	 * 卡号列表
	 */
	public function getCardList(){
		$card_list = model('manager/Cards')->getAllCardLists($this->request->get());
		return view('caravan/card_list',['card_list'=>$card_list]);
	}
	/**
	 * 卡详情
	 */
	public function getCardInfo($id)
	{
		$card_info = model('manager/Cards')->get(['id' => $this->request->get('id')]);
		return view('caravan/card_details',['card_info' => $card_info]);
	}
}

